package com.cyanite.playlv2api.types;

import com.cyanite.playlv2api.util.ParcelUtils;

import android.os.Parcel;
import android.os.Parcelable;

public class User implements PlayLv2Type, Parcelable {

    private Group<Badge> mBadges;
    private int mMsgCount;
    private int mBadgeCount;
    private Checkin mCheckin;
    private int mCheckinCount;
    private String mCreated;
    private String mEmail;
    private String mUserName;
    private int mFollowerCount;
    private int mFriendCount;
    private int mFriendRequestCount;
    private Group<User> mFriendsInCommon;
    private String mFriendstatus;
    private String mGender;
    private String mHometown;
    private String mId;
    private String mPhone;
    private String mPhoto;
    private Settings mSettings;
    private int mTipCount;
    private String mDescription;
    private int mScore;
    private String mDate;

    public User() {
    }

    private User(Parcel in) {
        mBadgeCount = in.readInt();
        mCheckinCount = in.readInt();
        mCreated = ParcelUtils.readStringFromParcel(in);
        mEmail = ParcelUtils.readStringFromParcel(in);
        mUserName = ParcelUtils.readStringFromParcel(in);
        mFollowerCount = in.readInt();
        mFriendCount = in.readInt();
        mFriendstatus = ParcelUtils.readStringFromParcel(in);
        mGender = ParcelUtils.readStringFromParcel(in);
        mHometown = ParcelUtils.readStringFromParcel(in);
        mId = ParcelUtils.readStringFromParcel(in);
        mPhone = ParcelUtils.readStringFromParcel(in);
        mPhoto = ParcelUtils.readStringFromParcel(in);
        mTipCount = in.readInt();

        mBadges = new Group<Badge>();
        int numBadges = in.readInt();
        for (int i = 0; i < numBadges; i++) {
            Badge badge = in.readParcelable(Badge.class.getClassLoader());
            mBadges.add(badge);
        }

        if (in.readInt() == 1) {
            mCheckin = in.readParcelable(Checkin.class.getClassLoader());
        }

        if (in.readInt() == 1) {
            mSettings = in.readParcelable(Settings.class.getClassLoader());
        }

        
        int numFriendsinCommon = in.readInt();
        if(numFriendsinCommon > 0){
            mFriendsInCommon = new Group<User>();
            for (int i = 0; i < numFriendsinCommon; i++) {
                User user = in.readParcelable(User.class.getClassLoader());
                mFriendsInCommon.add(user);
            }
        }
       
    }

    public static final User.Creator<User> CREATOR = new Parcelable.Creator<User>() {
        public User createFromParcel(Parcel in) {
            return new User(in);
        }

        @Override
        public User[] newArray(int size) {
            return new User[size];
        }
    };

    public String getDescription() {
        return mDescription;
    }

    public void setDescription(String description) {
        mDescription = description;
    }

    public Group<Badge> getBadges() {
        return mBadges;
    }

    public void setBadges(Group<Badge> badges) {
        mBadges = badges;
    }

    public int getMsgCount() {
        return mMsgCount;
    }

    public void setMsgCount(int count) {
        mMsgCount = count;
    }

    public Checkin getCheckin() {
        return mCheckin;
    }

    public void setCheckin(Checkin checkin) {
        mCheckin = checkin;
    }

    public int getCheckinCount() {
        return mCheckinCount;
    }

    public void setCheckinCount(int checkinCount) {
        mCheckinCount = checkinCount;
    }

    public String getCreated() {
        return mCreated;
    }

    public void setCreated(String created) {
        mCreated = created;
    }

    public String getDate() {
        return mDate;
    }

    public void setDate(String date)    {
        mDate = date;
    }

    public String getEmail() {
        return mEmail;
    }

    public void setEmail(String email) {
        mEmail = email;
    }

    public String getUserName() {
        return mUserName;
    }

    public void setUserName(String name) {
        mUserName = name;
    }

    public int getFollowerCount() {
        return mFollowerCount;
    }

    public void setFollowerCount(int followerCount) {
        mFollowerCount = followerCount;
    }

    public int getFriendCount() {
        return mFriendCount;
    }

    public void setFriendCount(int friendCount) {
        mFriendCount = friendCount;
    }

    public int getFriendRequestCount() {
        return mFriendRequestCount;
    }

    public void setFriendRequestCount(int friendRequestCount) {
        mFriendRequestCount = friendRequestCount;
    }

    public Group<User> getFriendsInCommon() {
        return mFriendsInCommon;
    }

    public void setFriendsInCommon(Group<User> friendsInCommon) {
        mFriendsInCommon = friendsInCommon;
    }

    public String getFriendstatus() {
        return mFriendstatus;
    }

    public void setFriendstatus(String friendstatus) {
        if (friendstatus.equals("1"))   {
            mFriendstatus = "friend";
        }
        else if (friendstatus.equals("2"))  {
            mFriendstatus = "pendingthem";
        }
        else if (friendstatus.equals("3"))  {
            mFriendstatus = "avaiable";
        }
        else if (friendstatus.equals("4"))  {
            mFriendstatus = "yourself";
        }
    }

    public String getGender() {
        return mGender;
    }

    public void setGender(String gender) {
        mGender = gender;
    }

    public String getHometown() {
        return mHometown;
    }

    public void setHometown(String hometown) {
        mHometown = hometown;
    }

    public String getId() {
        return mId;
    }

    public void setId(String id) {
        mId = id;
    }

    public String getPhone() {
        return mPhone;
    }

    public void setPhone(String phone) {
        mPhone = phone;
    }

    public String getPhoto() {
        return mPhoto;
    }

    public void setPhoto(String photo) {
        mPhoto = photo;
    }

    public Settings getSettings() {
        return mSettings;
    }

    public void setSettings(Settings settings) {
        mSettings = settings;
    }

    public int getTipCount() {
        return mTipCount;
    }

    public void setTipCount(int tipCount) {
        mTipCount = tipCount;
    }

    public int getScore()   {
        return mScore;
    }

    public void setScore(int score) {
        mScore = score;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(mBadgeCount);
        out.writeInt(mCheckinCount);
        ParcelUtils.writeStringToParcel(out, mCreated);
        ParcelUtils.writeStringToParcel(out, mEmail);
        ParcelUtils.writeStringToParcel(out, mUserName);
        out.writeInt(mFollowerCount);
        out.writeInt(mFriendCount);
        ParcelUtils.writeStringToParcel(out, mFriendstatus);
        ParcelUtils.writeStringToParcel(out, mGender);
        ParcelUtils.writeStringToParcel(out, mHometown);
        ParcelUtils.writeStringToParcel(out, mId);
        ParcelUtils.writeStringToParcel(out, mPhone);
        ParcelUtils.writeStringToParcel(out, mPhoto);
        out.writeInt(mTipCount);

        if (mBadges != null) {
            out.writeInt(mBadges.size());
            for (int i = 0; i < mBadges.size(); i++) {
                out.writeParcelable(mBadges.get(i), flags);
            }
        } else {
            out.writeInt(0);
        }

        if (mCheckin != null) {
            out.writeInt(1);
            out.writeParcelable(mCheckin, flags);
        } else {
            out.writeInt(0);
        }

        if (mSettings != null) {
            out.writeInt(1);
            out.writeParcelable(mSettings, flags);
        } else {
            out.writeInt(0);
        }

        if (mFriendsInCommon != null) {
            out.writeInt(mFriendsInCommon.size());
            for (int i = 0; i < mFriendsInCommon.size(); i++) {
                out.writeParcelable(mFriendsInCommon.get(i), flags);
            }
        } else {
            out.writeInt(0);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }
}
